package com.qf.controller;

import com.qf.entity.User;
import com.qf.vo.ResultVo;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/p")
public class ParamController {

    @RequestMapping("/test4/{id}/s/{name}")
    public ResultVo testParam4(@PathVariable("id") Integer id,@PathVariable("name") String name){
        System.out.println(id);
        System.out.println(name);
        return  new ResultVo(200,"ok",null);
    }


    @RequestMapping("/test3")
    public ResultVo testParam3(String[] hobby){
        for (int i = hobby.length - 1; i >= 0; i--) {
            System.out.println(hobby[i]);
        }
        return new ResultVo(200,"ok",null);
    }

    @RequestMapping("/test2")
    public ResultVo testParam1(@RequestBody User user){
        System.out.println(user);
        return new ResultVo(200,"ok",null);
    }

    @RequestMapping("/test1")
    public ResultVo testParam1(@RequestParam("studentid") Integer id,
                               String name,
                               Boolean gender,
                               @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date birth){
        System.out.println(id);
        System.out.println(name);
        System.out.println(gender);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(simpleDateFormat.format(birth));

        System.out.println(birth);
        return new ResultVo(200,"ok",null);
    }

}
